#coding:utf-8
# -*- coding: utf-8 -*-
import time
import datetime

def timestamp2datetime(_timestamp):
    """时间戳-->datetime"""
    if isinstance(_timestamp, datetime.datetime):
        return datetime
    timeArray = time.localtime(_timestamp)
    otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    return otherStyleTime

def datetime2timestamp(_datetime):
    """datetime-->时间戳"""
    if isinstance(_datetime, float) or isinstance(_datetime, int):
        return _datetime
    return int(time.mktime(_datetime.timetuple()))


if __name__ == '__main__':
    t = time.time()
    print(t, timestamp2datetime(t))

    d = datetime.datetime.now()
    print(d, datetime2timestamp(d))
